package playGround;
import be.kuleuven.cs.som.annotate.*;

/**
 * @author Niels
 *
 */
@Value
public enum Scale {
	FAHRENHEIT('F'), CELCIUS('C'),KELVIN('K') ;
	
	@Raw
	private Scale(char unit){
		this.unit = unit;
	}
	private final char unit;
	
	@Raw @Immutable @Basic
	public char getUnit(){
		return this.unit;
	}
	/**
	 * 
	 * @param 	oldTemperatureScale
	 * 			The old temperature scale.
	 * @param 	newTemperatureScale
	 * 			The new temperature scale.
	 * @param 	temperature
	 * 			The given temperature whose scale is about to get changed.
	 * @return	The temperature, expressed in the new scale.
	 * 			| if (oldTemperatureScale== Scale.CELCIUS)
	 * 			|		
	 */
	public static int changeScale(Scale oldTemperatureScale, Scale newTemperatureScale, int temperature){
		if(oldTemperatureScale== Scale.CELCIUS){
			if(newTemperatureScale == Scale.FAHRENHEIT)
				return ((temperature -32)*5/9);
			if(newTemperatureScale==Scale.KELVIN)
				return temperature+273;
			if(newTemperatureScale == Scale.CELCIUS)
				return temperature;
		}
		else if(oldTemperatureScale == Scale.FAHRENHEIT){
			return changeScale(Scale.CELCIUS,newTemperatureScale,temperature*9/5+32);
		}
		
		else if(oldTemperatureScale == Scale.KELVIN){
			return changeScale(Scale.CELCIUS,newTemperatureScale,temperature-273);
		}
		return temperature;
		
	}


}
